fetch('http://chst.vip:1234/api/getcategorytitle')
.then(function(c){
    return c.json()
})
.then(function(b){
    console.log(b);
    let str='';
    let newarr=[];
    b.result.forEach(item=> {
        str +=`<li>
                    <h4>${item.title} <span></span></h4>
                    <div>
                        
                    </div>
                </li>`
        newarr.push(`${item.titleId}`)
        console.log(newarr);
        
    });
    console.log($('ul'));
    let ul=document.querySelector('ul')
    ul.innerHTML=str;

    newarr.forEach((item,index)=>{
        let str1=''
        fetch('http://chst.vip:1234/api/getcategory?titleid='+item)
        .then(function(a){
            return a.json();
        })
        .then(function(b){
            console.log(b);
            b.result.forEach(item => {
                str1 +=` <p categoryId=${item.categoryId}>
                            ${item.category}
                        </p>`
            });
            console.log(str1);
            let div = document.querySelectorAll('ul li div')
            div[index].innerHTML=str1;
        })
    })
    console.log($('ul'));
    $('ul li').click(function(){
        $(this).find('div').slideToggle().parent().siblings().find('div').slideUp();
    })
    $(function(){
        $('ul li div').slideUp()
    })
})
.then(function(){
    $('ul li div').on('click','p',function(e){
        let categoryId = $(this).attr('categoryId')
        console.log($(this).attr('categoryId'));
        location.href='./category_1.html?categoryId='+categoryId;
    })
})
